<!DOCTYPE html>
<!-- saved from url=(0052)http://getbootstrap.com/docs/4.0/examples/dashboard/ -->
<html lang="en" xmlns:th="http://www.thymeleaf.org">

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<meta name="description" content="">
		<meta name="author" content="">

		<title>Dashboard Template for Bootstrap</title>
		<!-- Bootstrap core CSS -->
		<link href="asserts/css/bootstrap.min.css" rel="stylesheet">

		<!-- Custom styles for this template -->
		<link href="asserts/css/dashboard.css" rel="stylesheet">
	</head>

	<body>

	<div th:insert="common/bar::top"></div>

		<div class="container-fluid">
			<div class="row">
				<div th:insert="common/bar::#left"></div>
				<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
					<div class="table-responsive">
						<form id="studentInfoForm">
							<div class="form-group">
								<label>学号:</label>
								<input name="stdentID" disabled type="text" class="form-control" placeholder="" th:value="${session.studentInfo.studentID}">
							</div>
							<div class="form-group">
								<label>姓名:</label>
								<input name="name" disabled type="text" class="form-control" placeholder="" th:value="${session.studentInfo.name}">
							</div>
							<div class="form‐group">
								<label>学校:</label>
								<input name="universityName" disabled type="text"  class="form-control" placeholder="" th:value="${session.studentInfo.universityName}">
							</div>
							<div class="form‐group">
								<label>学院:</label>
								<input name="department" disabled type="text" class="form-control" placeholder="" th:value="${session.studentInfo.departmentName}">
							</div>
							<div class="form‐group">
								<label>班级:</label>
								<input name="className" type="text" disabled class="form-control" placeholder="" th:value="${session.studentInfo.className}">
							</div>
							<div class="form-group">
								<label>昵称:</label>
								<input name="nickName" type="text" class="form-control" placeholder="" th:value="${session.studentInfo.nickName}">
							</div>
							<div class="form‐group">
								<label>邮箱:</label>
								<input name="email" type="text" class="form-control" placeholder="zhangsan@atguigu.com" th:value="${session.studentInfo.emial}">
							</div>
							<div class="form‐group">
								<label>手机:</label>
								<input name="phoneNumber" type="text" class="form-control" placeholder="" th:value="${session.studentInfo.phoneNumber}">
							</div>
							<br>
							<div class="form‐group">
								<label>头像:</label><br>
								<img id="show" th:src="${session.studentInfo.image}" alt=""><br>
								<input type="file" id="myfile" name="image"  onchange="showImage()">

							</div>
							<br>
							<!--
							<div class="form-group">
								<label>department</label>
								<select class="form-control">
									<option th:value="${dept.deptno}" th:each="dept:${depts}" th:text="${dept.dname}">1</option>
								</select>
							</div>
							-->
							<br>
						</form>
						<button type="submit" class="btn btn-primary" onclick="studentInfoSubmit()">添加</button>
					</div>
				</main>
			</div>
		</div>

	<script type="text/javascript" src="asserts/js/jquery-3.2.1.slim.min.js"></script>
	<script type="text/javascript" src="js/jquery.min.js"></script>
	<script src="asserts/js/popper.min.js"></script>
	<script src="asserts/js/feather.min.js"></script>
	<script src="asserts/js/bootstrap.min.js"></script>
	<script type="text/javascript">
		//图片回显
		function showImage() {
			var reader = new FileReader();
			var file = document.getElementById("myfile").files[0];
			console.log(file);
			reader.onload=function (e) {
				///console.log(this.result);
				document.getElementById('show').src=this.result;
			};
			reader.readAsDataURL(file);
		}


		function verifyLoginStatus() {
			//验证登录状态
			console.log("1");
			var message = document.getElementById("mystatus").innerText;
			console.log(message);
			if(message == '请先登录'){
				alert("请登录");
				location.href="login";
				return '1';
			}
			return '2';
		}

		//表单提交
		function studentInfoSubmit() {

			var status = verifyLoginStatus();

			if(status == '2'){
				var form = new FormData(document.getElementById("studentInfoForm"));

				$.ajax({
					url:"finishStudentInfo.do",
					type:"post",
					dataType:"html",
					data:form,
					cache:false,
					processData:false,
					contentType:false,
					success: function (data) {
						console.log("success");
						alert("修改成功！");
						location.href="index";

					},
					error:function (data) {
						console.log("error");
					}
				})
			}

		}



	</script>

	</body>

</html>